﻿using AdminSystem.Applications;
using AdminSystem.Domain.User;
using AdminSystem.Repositories;
using AdminSystem.Write.API.Command.EnterprisesCommand;
using MediatR;

namespace AdminSystem.Write.API.Handers.EnterpriseHander
{
    public class EnterpriseQueryCommandsHandler : IRequestHandler<EnterpriseQueryCommand, ApiResult<Enterprise>>
    {
        public EnterpriseQueryCommandsHandler(IRepository<Enterprise> repository)
        {
            Repository = repository;
        }

        public IRepository<Enterprise> Repository { get; }
        /// <summary>
        /// 查询企业信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<ApiResult<Enterprise>> Handle(EnterpriseQueryCommand request, CancellationToken cancellationToken)
        {
            ApiResult<Enterprise> result = new ApiResult<Enterprise>();
            result.statusCode = StatusCode.Success;
            result.Message = "查询成功";
            var list = Repository.GetAll();
            var entity = list.Result.FirstOrDefault();
            result.Data = entity;
            return Task.FromResult(result);
        }
    }
}
